package com.atguigu.mvc.controller.handler;

import com.atguigu.mvc.entity.Department;
import com.atguigu.mvc.entity.Employee;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author : zzf
 * @version : 1.0
 * @date : 2021/1/11
 */

@Controller
public class UploadController {
    @RequestMapping("test/upload")
    public String testUpload(String username, MultipartFile picture) throws IOException {
        System.out.println("username = " + username);

        String inputName = picture.getName();
        System.out.println("inputName = " + inputName);

        String originalFilename = picture.getOriginalFilename();
        System.out.println("originalFilename = " + originalFilename);

        boolean empty = picture.isEmpty();
        System.out.println("empty = " + empty);

        long size = picture.getSize();
        System.out.println("size = " + size);

        byte[] bytes = picture.getBytes();
        for (byte aByte : bytes) {
            System.out.print(aByte + " ");
        }

        System.out.println();

        InputStream inputStream = picture.getInputStream();
        System.out.println("inputStream = " + inputStream);
        return "target";
    }

    @RequestMapping(value="ajax/test/one")
    @ResponseBody
    public Department testOne(String userName,String userPwd){
        System.out.println("userName = " + userName);
        System.out.println("userPwd = " + userPwd);
        return new Department("001","zz");
    }
}
